package com.whty.mongodemo.model;

import io.vertx.core.json.JsonObject;

public class JsonResult extends JsonObject {

  public JsonResult(Integer code, String msg, Object data) {
    this.put("code", code)
      .put("msg", msg)
      .put("data", data);
  }

  public JsonResult(Integer code, String msg) {
    this.put("code", code)
      .put("msg", msg)
      .put("data", null);
  }

  public static JsonResult success() {
    return new JsonResult(0, "success");
  }

  public static JsonResult success(Object data) {
    return new JsonResult(0, "success", data);
  }

  public static JsonResult failed() {
    return new JsonResult(1, "failed");
  }

  public static JsonResult failed(String msg) {
    return new JsonResult(1, msg);
  }
}
